[SR-12583] Added checks to catch 'foo() {} {}' and 'foo {} () {}' #32000
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Addresses two parse problems in SR-12583, where (single) trailing closures should not be parsed in the neighborhood of other trailing closures. The parse trees for both forms are identical but the Parser takes two paths to get there. @jckarter entered the original bug.
Several questions:
Is this the right place/method to do this? I just put an if(condition) check in two places in the parser and emitted a diagnostic. Should the check be in the CallExpr::create() instead of in the parser?
I'm not completely sure that there's not a valid parse like this. The parse tree looks like the below. It indents poorly here but it's a call with a trailing closure containing another call with a trailing closure. I'm still thinking through whether there's some legitimate Swift code that could generate that:
(call_expr (call_expr (paren_expr trailing-closure)) (paren_expr trailing-closure))
The diagnostic just says 'double trailing closures' right now, which is accurate but not clear enough. Any suggestions to improve the wording are welcome. I will think about it further.
This may interfere or interact with work on multiple trailing closures that @xedin (I think) is working on now.
The swift in the examples is kind of aesthetically displeasing but logically OK. I'm not sure this should actually be disallowed.
Resolves SR-12583.